package com.wang.springbootinit.common;

import lombok.Data;

import java.io.Serializable;

/**
 * 通用返回类
 *
 * @param <T>
 */
@Data
public class BaseResponsePage<T> extends PageRequest implements Serializable {

    private int code;

    private T data;

    private String message;

    public BaseResponsePage(int code, T data, String message) {
        this.code = code;
        this.data = data;
        this.message = message;
    }

    /**
     * 分页
     * @param code
     * @param data
     * @param message
     * @param current
     * @param size
     * @param total
     */
    public BaseResponsePage(int code, T data, String message, int  current, int size, int total) {
        this.code = code;
        this.data = data;
        this.message = message;
        this.setCurrent(current);
        this.setPageSize(size);
        this.setTotal(total);
    }

    public BaseResponsePage(int code, T data) {
        this(code, data, "");
    }

    public BaseResponsePage(ErrorCode errorCode) {
        this(errorCode.getCode(), null, errorCode.getMessage());
    }
}
